﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _91随机打乱数组元素
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            int[] arr1 = { 6, 1, 9, 11, 3, 0 };

            DisSort(arr1);

            for (int i = 0; i < arr1.Length; i++)
            {
                Console.WriteLine(arr1[i]);
            }
        }

        private static void DisSort(int[] array)
        {
            //创建随机数对象
            Random ran = new Random();
            for (int i = 0; i < array.Length; i++)
            {
                int index = ran.Next(0, array.Length);//左闭右开,能取到0 但是取不到array.Length
                int temp = array[i];
                array[i] = array[index];
                array[index] = temp;
            }
        }
    }
}